package com.flying.planewar;

import java.awt.*;

/**
 * @author 刘鹏飞
 * @Classname GameObject
 * @Date 2024/12/17 15:37
 * @Created by 刘鹏飞
 * @Description 游戏物体根类
 */
public class GameObject {
    Image image;
    double  x,y;  // 游戏物体的坐标
    int speed; // 游戏物体的速度
    int width,height;  // 物体的宽度和高度

    public GameObject() {
    }

    public GameObject(Image image, double x, double y,int speed) {
        this(image,x,y);
        this.speed=speed;
    }

    public GameObject(Image image, double x, double y) {
        this.image = image;
        this.x = x;
        this.y = y;
        if (image!=null){
            this.width=image.getWidth(null);
            this.height=image.getHeight(null);
        }
    }

    public GameObject(Image image, double x, double y, int speed, int width, int height) {
        this.image = image;
        this.x = x;
        this.y = y;
        this.speed = speed;
        this.width = width;
        this.height = height;
    }


    // 画自己的方法
    public void drawMyself(Graphics g ){
        g.drawImage(image,(int)x,(int)y, null);
    }


    // 获取游戏物体所在矩形
    public Rectangle getRectangle(){
        return new Rectangle((int)x,(int)y,width,height);
    }

}
